package com.winhxd.b2c.common.feign.product;

import com.winhxd.b2c.common.constant.BusinessCode;
import com.winhxd.b2c.common.constant.ServiceName;
import com.winhxd.b2c.common.domain.PagedList;
import com.winhxd.b2c.common.domain.ResponseResult;
import com.winhxd.b2c.common.domain.product.condition.ProductTagCondition;
import com.winhxd.b2c.common.domain.product.model.ProductTag;
import feign.hystrix.FallbackFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.List;

/**
 * @author cuipengbo
 * @create 2019-01-05 17:11
 * @desc 商品服务管理
 **/
@FeignClient(value = ServiceName.PRODUCT_SERVICE, fallbackFactory = ProductTagServiceFallback.class)
public interface ProductTagServiceClient {

    /**
     * 根据服务id编辑商品服务信息状态
     * @param condition
     * @return
     */
    @RequestMapping(value = "/productTag/8310/v1/modifyProductTagStatusById", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    ResponseResult<Integer> modifyProductTagStatusById(@RequestBody ProductTagCondition condition);

    /**
     * 根据服务id删除该商品服务
     * @param id
     * @return
     */
    @RequestMapping(value = "/productTag/8311/v1/deleteProductTagById/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    ResponseResult<Integer> deleteProductTagById(@PathVariable(value = "id") long id);

    /**
     * 查询商品服务列表
     * @param productTagCondition
     * @return
     */
    @RequestMapping(value = "/productTag/8312/v1/findProductTagList", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    ResponseResult<PagedList<ProductTag>> findProductTagList(@RequestBody ProductTagCondition productTagCondition);

    /**
     * 根据服务id查询商品服务
     * @return
     */
    @RequestMapping(value = "/productTag/8313/v1/getProductTagById/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    ResponseResult<ProductTag> getProductTagById(@PathVariable(value = "id") long id);

    /**
     * 新增商品服务
     * @param condition
     * @return
     */
    @RequestMapping(value = "/productTag/8314/v1/savaProductTag", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    ResponseResult<Integer> savaProductTag(@RequestBody ProductTagCondition condition);


    /**
     * 保存商品服务信息
     * @param condition
     * @return
     */
    @RequestMapping(value = "/productTag/8315/v1/savaOrUpdateProductTag",method = RequestMethod.POST)
    ResponseResult<Integer> savaOrUpdateProductTag(@RequestBody ProductTagCondition condition);

    /**
     * 根据条件查询商品服务信息
     * @param condition
     * @return
     */
    @RequestMapping(value = "/productTag/8316/v1/findProductTagByModel",method = RequestMethod.POST)
    ResponseResult<List<ProductTag>> findProductTagByModel(@RequestBody ProductTagCondition condition);

}

@Component
class ProductTagServiceFallback implements FallbackFactory<ProductTagServiceClient> {
    private static final Logger logger = LoggerFactory.getLogger(ProductTagServiceFallback.class);

    @Override
    public ProductTagServiceClient create(Throwable throwable) {
        return new ProductTagServiceClient(){
            @Override
            public ResponseResult<Integer> modifyProductTagStatusById(ProductTagCondition condition) {
                logger.error("ProductTagTagClient -> modifyProductTagStatusById", throwable);
                return new ResponseResult<>(BusinessCode.CODE_1001);
            }

            @Override
            public ResponseResult<Integer> deleteProductTagById(long id) {
                logger.error("ProductTagTagClient -> deleteProductTagById", throwable);
                return new ResponseResult<>(BusinessCode.CODE_1001);
            }

            @Override
            public ResponseResult<PagedList<ProductTag>> findProductTagList(ProductTagCondition productTagCondition) {
                logger.error("ProductTagTagClient -> findProductTagList", throwable);
                return new ResponseResult<>(BusinessCode.CODE_1001);
            }

            @Override
            public ResponseResult<ProductTag> getProductTagById(long id) {
                logger.error("ProductTagTagClient -> getProductTagById", throwable);
                return new ResponseResult<>(BusinessCode.CODE_1001);
            }

            @Override
            public ResponseResult<Integer> savaProductTag(ProductTagCondition condition) {
                logger.error("ProductTagTagClient -> savaProductTag", throwable);
                return new ResponseResult<>(BusinessCode.CODE_1001);
            }

            @Override
            public ResponseResult<Integer> savaOrUpdateProductTag(ProductTagCondition condition) {
                logger.error("ProductTagTagClient -> savaOrUpdateProductTag", throwable);
                return new ResponseResult<>(BusinessCode.CODE_1001);
            }

            @Override
            public ResponseResult<List<ProductTag>> findProductTagByModel(ProductTagCondition condition) {
                logger.error("ProductTagTagClient -> findProductTagByModel", throwable);
                return new ResponseResult<>(BusinessCode.CODE_1001);
            }

        };
    }
}
